
import React,{Component} from 'react';


export default class Reftest extends Component{

    constructor(props) {
        super(props);
        this.input1 = React.createRef();
        this.input3 = React.createRef();
    }

    componentDidMount() {
        this.input.focus()
        this.input1.current.value = 1
        // this.refs.input3.focus();   //不推荐使用
        this.props.onRef(this.input3)

    }

    render() {
        return (
            <div>
                <div>第一种：<input ref={(res)=> this.input = res } type="text"/></div>
                <div>第二种：<input ref={this.input1}  type="text"/></div>
                {/*<div>第三种：<input ref='input3' type="text"/></div>*/}
                <div>
                    将ref传给 父组件
                    <input ref={this.input3} type="text"/>
                </div>
            </div>
        )

    }

}
